package com.qige.homework;

public class homework1 {
    public static void main(String[] args) {
        /*try {
            Person person = new Person("迪迦",-10);
        } catch (Exception e) {
            e.printStackTrace();
        }*/
        try {
            Person person2 = new Person();
            person2.setLifeValue(10);
            person2.setLifeValue(-10);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
class NoLifeValueException extends RuntimeException{
    public NoLifeValueException() {
    }

    public NoLifeValueException(String message) {
        super(message);
    }
}
class Person{
    private String name;
    private int lifeValue;

    public Person() {
    }

    public Person(String name, int lifeValue) {
        this.name = name;
        this.lifeValue = lifeValue;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getLifeValue() {
        return lifeValue;
    }

    public void setLifeValue(int lifeValue) {
        if (lifeValue < 0) {
            throw new NoLifeValueException("生命值不能为负数：" + lifeValue);
        }
        this.lifeValue = lifeValue;
    }
}